<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
	
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
	}
	
	function index(){
		$this->load->helper('captcha');
		
		if($this->input->post('act') == 'login'){
			//$captcha		=	$_SESSION['captcha']; 
			
			$data = array(
				'captcha'  => trim($_POST['captcha']),
				'username' => $_POST['username'],
				'password' => $_POST['password'],
				'smscode' => $_POST['smscode'],
			);
			
			$ret = array('msg'=>'数据错误','url'=>'');
			
			if ($data['captcha'] =="" ){
				$ret['msg']='验证码不能为空';
				echo json_encode($ret); exit;
			}elseif ($data['captcha'] != $_SESSION['captcha']){
				$ret['msg']='验证码不正确';
				echo json_encode($ret); exit;
			}elseif ($data['username']==""){
				$ret['msg']='账号不能为空';
				echo json_encode($ret); exit;
			}elseif ($_POST['password']==""){
				$ret['msg']='密码不能为空';
				echo json_encode($ret); exit;
			}
			else{
				$this->load->model('systemadmin_user_model');
				$this->load->model('systemadmin_model');
				$user = $this->systemadmin_user_model->check_login($this->input->post('username'),$this->input->post('password'));
				$user['user_id'] = $user['id'];
				
				if(isset($user['user_id'])){
					if($user['status'] == 1){
						$user['login_curr_time'] = time();
						$user['last_login_time'] = $user['login_time'];
						$user['last_login_ip'] = $user['login_ip'];
						
						$systype_info = $this->systemadmin_user_model->get_user_adminlist($user['type_id']);
						
						$user['type_name'] = $systype_info['name'];
						$this->session->set_userdata('admin_user',$user);
						
						$ret['msg']='';
						$last_url = trim($this->input->post('last_url'));
						
						if( $last_url == ''){
							$ret['url']='/sys_admin/login/success';
						}else{
							$ret['url']=$last_url;
						}
						
						$usertime['login_time'] = time();
						$usertime['login_ip'] = $this->js->get_ip();
						$usertime['last_login_time'] = $user['login_time'];
						$usertime['last_login_ip'] = $user['login_ip'];
						$this->systemadmin_model->update($user['id'],$usertime);
						echo json_encode($ret);
						exit;
					}else{
						$ret['msg']='此账号已经关闭';
						echo json_encode($ret);
						exit;
					}
					 
				}else{
					$ret['msg']='账号或密码或验证码错误';
					echo json_encode($ret);
					exit;
				}
			}
		}else{
			$data['last_url']		    = trim($this->input->get('last_url'));
			$data['title'] 				= "后台登陆";
			
			$this->load->view('/sys_admin/login', $data);
		}
	}
	
	function success(){
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
		$this->load->view('/sys_admin/index');
	}
	
	
	
	function sendsms(){
		$username = $this->input->post('username');
		$this->load->model('User_model', 'user');
		$user_obj = $this->user->get_one(array('username'=>$username),'user_id,phone');
		if($user_obj){
			$this->load->library('phone');
			$smscode = $this->phone->randstr();
			$msg = "后台登录手机验证码为：".$smscode;
			$res = $this->phone->send($user_obj['phone'],$msg);
			$this->user->update(array('smscode'=>$smscode, 'smstime'=>time()), array('user_id'=>$user_obj['user_id']));
			$ret['msg']='验证码发送成功,24小时内有效';
			echo json_encode($ret);exit;
		}
		$ret['msg']='用户名不存在';
		echo json_encode($ret);exit;
	}
	
}
=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
    
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
	}
	
	function index(){
		$this->load->helper('captcha');
		
		if($this->input->post('act') == 'login'){
			//$captcha		=	$_SESSION['captcha']; 
			
			$data = array(
				'captcha'  => trim($_POST['captcha']),
				'username' => $_POST['username'],
				'password' => $_POST['password'],
				'smscode' => $_POST['smscode'],
			);
			
			$ret = array('msg'=>'数据错误','url'=>'');
			
			if ($data['captcha'] =="" ){
				$ret['msg']='验证码不能为空';
				echo json_encode($ret); exit;
			}elseif ($data['captcha'] != $_SESSION['captcha']){
				$ret['msg']='验证码不正确';
				echo json_encode($ret); exit;
			}elseif ($data['username']==""){
				$ret['msg']='账号不能为空';
				echo json_encode($ret); exit;
			}elseif ($_POST['password']==""){
				$ret['msg']='密码不能为空';
				echo json_encode($ret); exit;
			}
			else{
				$this->load->model('systemadmin_user_model');
				$this->load->model('systemadmin_model');
				$user = $this->systemadmin_user_model->check_login($this->input->post('username'),$this->input->post('password'));
				$user['user_id'] = $user['id'];
				
				if(isset($user['user_id'])){
					if($user['status'] == 1){
						$user['login_curr_time'] = time();
						$user['last_login_time'] = $user['login_time'];
						$user['last_login_ip'] = $user['login_ip'];
						
						$systype_info = $this->systemadmin_user_model->get_user_adminlist($user['type_id']);
						
						$user['type_name'] = $systype_info['name'];
						$this->session->set_userdata('admin_user',$user);
						
						$ret['msg']='';
						$last_url = trim($this->input->post('last_url'));
						
						if( $last_url == ''){
							$ret['url']='/sys_admin/login/success';
						}else{
							$ret['url']=$last_url;
						}
						
						$usertime['login_time'] = time();
						$usertime['login_ip'] = $this->js->get_ip();
						$usertime['last_login_time'] = $user['login_time'];
						$usertime['last_login_ip'] = $user['login_ip'];
						$this->systemadmin_model->update($user['id'],$usertime);
						echo json_encode($ret);
						exit;
					}else{
						$ret['msg']='此账号已经关闭';
						echo json_encode($ret);
						exit;
					}
					 
				}else{
					$ret['msg']='账号或密码或验证码错误';
					echo json_encode($ret);
					exit;
				}
			}
		}else{
			$data['last_url']		    = trim($this->input->get('last_url'));
			$data['title'] 				= "后台登陆";
			
			$this->load->view('/sys_admin/login', $data);
		}
	}
	
	function success(){
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
		$this->load->view('/sys_admin/index');
	}
	
	
	
	function sendsms(){
		$username = $this->input->post('username');
		$this->load->model('User_model', 'user');
		$user_obj = $this->user->get_one(array('username'=>$username),'user_id,phone');
		if($user_obj){
			$this->load->library('phone');
			$smscode = $this->phone->randstr();
			$msg = "后台登录手机验证码为：".$smscode;
			$res = $this->phone->send($user_obj['phone'],$msg);
			$this->user->update(array('smscode'=>$smscode, 'smstime'=>time()), array('user_id'=>$user_obj['user_id']));
			$ret['msg']='验证码发送成功,24小时内有效';
			echo json_encode($ret);exit;
		}
		$ret['msg']='用户名不存在';
		echo json_encode($ret);exit;
	}
	
}
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
